//
//  UserLogon.m
//  bmwTest
//
//  Created by Neutrino on 11-5-13.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "UserLogon.h"


@implementation UserLogon
@synthesize IS_ACCEPT;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
//-------------
-(void)alertBox:(NSString*)msg
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msg 
                                                    message:@""
                                                   delegate:self 
                                          cancelButtonTitle:@"Yes" 
                                          otherButtonTitles:@"No", nil];
    [alert show];
    [alert release];
}
-(IBAction)onPress
{
    NSString* name = [userName text];
    NSString* passwd = [userPasswd text];
    if([name length] == 0){
        
        [self alertBox:@"Please input your name"];
        return;
    }
    if([self accountCheck:name :passwd]){
        //[self dealloc]; 
        IS_ACCEPT = YES;
    }
}
-(BOOL)accountCheck:(NSString*)name: (NSString*)passwd
{
    if([name isEqualToString:@"aaa"] && [passwd isEqualToString:@"aaa"])
    {
        
        return YES;
    }
    else
        [self alertBox:@"Wrong user name or password"];
    
    return NO;
}

//-------------
#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    IS_ACCEPT = NO;
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
	return YES;
}

@end
